package com.ebelter.myehc.ui.fragments.trends;



import com.ebelter.btcomlib.bases.fragment.BaseFragment;

import com.ebelter.btcomlib.models.bluetooth.products.three2one.ThreeOneManager;

import com.ebelter.btcomlib.utils.AppUtils;
import com.ebelter.btcomlib.utils.CommonUtils;
import com.ebelter.btcomlib.utils.NumUtils;
import com.ebelter.btcomlib.utils.TimeUtils;

import com.ebelter.btcomlib.views.ChartView3;
import com.ebelter.btcomlib.views.CombinView7;
import com.ebelter.btcomlib.views.CombinView8;
import com.ebelter.myehc.R;

import com.ebelter.myehc.models.http.response.device_resports.Cholesterol_R;
import com.ebelter.myehc.utils.EHCCommonUtils;


import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.ebelter.btcomlib.bases.activity.BaseActivity.getString_;
import static com.ebelter.myehc.ui.fragments.trends.Trend_XueYa_Fragment.setCb8SrcRes;
import static com.ebelter.myehc.ui.fragments.trends.Trend_XueYa_Fragment.setCb8Title;

/**
 * 趋势血压
 */

public class Trend_ZDGCH_Fragment extends BaseFragment {
    public static final String TAG = "Trend_TiWen_Fragment";
    private static final int[] levelColors={0xff18d5e5,0xff14e34e,0xffffcc00};

    CombinView7 zdgch_cb7;
    CombinView8 zdgch_cb8;
    ChartView3 zdgch_chartview3;

    @Override
    protected int setLayoutResouceId() {
        return R.layout.fragment_trend_zongdanguchun;
    }


    public void setReportData(Cholesterol_R reportData) {
        if (reportData==null||reportData.resultCode!=1||reportData.resultData==null){
            return;
        }




        //y轴坐标对应的数据
        List<Float> xyYValue = new ArrayList<>();
        for (int i = 0; i < 7; i++) {//Y轴的刻度值
            xyYValue.add((float)(i *30));
        }
        //x轴坐标对应的数据
        List<String> oneXValue = new ArrayList<>();
        List<String> disXValue = new ArrayList<>();
        List<Integer> xPointColor = new ArrayList<>();

        Map<String, Float> xyValue = new HashMap<>();

      //  Map<String, Float> maiboValue = new HashMap<>();

        float newestCholestero = 0;

        if (reportData.resultData.chartList!=null){

        //dateType:日期类型 1:年 2:月 3周: 4:天
        //measureType:1:血糖 2:血压 3:血氧 4:体温 5:尿酸 6:总胆固醇 7:人体成份
        for (int i=0;i<reportData.resultData.chartList.size();i++){
            Cholesterol_R.ResultDataBean.ChartListBean data = reportData.resultData.chartList.get(i);


            if (data.cholesterolAvg==0){
                continue;
            }
            String timeParam="";
            String disTimeParam="";
            if (reportData.resultData.dateType==1){
                Date date= TimeUtils.parseFormatter91Time(data.timeParam);
                timeParam= CommonUtils.getMonths(NumUtils.string2Int(TimeUtils.formatTime12(date.getTime())));
                disTimeParam=timeParam;
            }else if (reportData.resultData.dateType==2){
                timeParam=String.format(getString_(R.string.Week_int),data.timeParam);
                disTimeParam=timeParam;
            }else if (reportData.resultData.dateType==3){
                Date date2= TimeUtils.parseFormatter3Time(data.timeParam);
                timeParam=TimeUtils.formatTime11(date2.getTime());
                disTimeParam=timeParam;
            }else if (reportData.resultData.dateType==4){
                Date date3= TimeUtils.parseFormatter1Time(data.timeParam);
                timeParam=TimeUtils.formatTime13(date3.getTime());
                disTimeParam=TimeUtils.formatTime4(date3.getTime());
            }

            oneXValue.add(timeParam);
            disXValue.add(disTimeParam);
            xyValue.put(timeParam, data.cholesterolAvg);
            newestCholestero=data.cholesterolAvg;
            xPointColor.add(levelColors[ThreeOneManager.computerTZHHResult(data.cholesterolAvg)]);



        }

        }

        if (reportData.resultData.summaryList!=null&&reportData.resultData.summaryList.size()>0){
            setCb8Title(zdgch_cb8,2, NumUtils.disFlZero(reportData.resultData.summaryList.get(0).cholesterolMin,N2));
            setCb8Title(zdgch_cb8,3,NumUtils.disFlZero(reportData.resultData.summaryList.get(0).cholesterolMax,N2));
            setCb8Title(zdgch_cb8,4,NumUtils.disFlZero(reportData.resultData.summaryList.get(0).cholesterolAvg,N2));
            setCb8SrcRes(zdgch_cb8, EHCCommonUtils.getDisplaySrcRes(reportData.resultData.summaryList.get(0).cholesterolAvg,newestCholestero));
        }

        if (zdgch_chartview3!=null) {
            zdgch_chartview3.setxPointColor(xPointColor);
            zdgch_chartview3.setdisXValue(disXValue);
            zdgch_chartview3.setValue(xyValue,oneXValue,xyYValue);
            zdgch_chartview3.src2end();
        }



    }

    @Override
    protected void initView() {
        super.initView();
        FV();
    }

    private void FV() {
        zdgch_cb7=mRootView.findViewById(R.id.zdgch_cb7);
        zdgch_cb8=mRootView.findViewById(R.id.zdgch_cb8);
        if (AppUtils.en==AppUtils.getLocalStr()){
            zdgch_cb7.setTitleSizes(13);
            zdgch_cb8.setTitleSizes(14);
        }
        zdgch_chartview3=mRootView.findViewById(R.id.zdgch_chartview3);
        zdgch_chartview3.warringTem=1000;
        zdgch_chartview3.yOriStart=0;
    }
}
